

clear
estimates clear 
set more off

* load data

cd "/Users/zerenli1992/Dropbox/anti_corruption/replication_file/result"
*use  "/Users/zerenli1992/Dropbox/course/Duke 2016-FALL/RA_Prof. Manion/anti_corruption_project/county_leader/pref_prov.dta", replace

use  "/Users/zerenli1992/Dropbox/anti_corruption/replication_file/pref_prov_22.dta", replace

tab doublecorrect

g turnover = "No Change" if doublecorrect == "0"
replace turnover = "Promotion" if doublecorrect == "1" 
replace turnover =  "Lateral Transfer"  if doublecorrect == "2" 
replace turnover =   "Retirement" if  doublecorrect == "1z" 
replace turnover =  "Retirement" if   doublecorrect== "3" 
replace turnover =  "Dismissed for Corruption" if doublecorrect == "4" 
replace turnover =    "Death" if  doublecorrect == "5" 
replace turnover =  "Demotion" if  doublecorrect == "6" 

* clean education variable
replace con_college = 0 if con_college == .


g sec_dismiss = 0
replace sec_dismiss = 1 if doublecorrect == "4"
* set panel variable
xtset cityID year

* set interaction
g purgeconnection = purge_cen_cum*first_con_ps
global interaction  purgeconnection purge_cen_cum first_con_ps 

* province-level controls
global p_control gdp_growth_rel  fiscal_growth_rel
global cor_control pref_corruption prov_corruption
* individual controls
g sec_age_2 = sec_age^2
g ps_term_2 = ps_term^2
global i_control female minority edu sec_age sec_age_2 ps_term  ps_term_2 firstjob_yr party_yr  dic  law_enforce org prop youth_league


* triple interaction
g xi_connection =  prov_xi_faction*first_con_ps
g xi_purge =  prov_xi_faction*purge_cen_cum
g xi_connection_purge = prov_xi_faction*purge_cen_cum*first_con_ps
global triple xi_connection_purge purgeconnection xi_connection xi_purge purge_cen_cum first_con_ps  prov_xi_faction

global prov_control roving prov_ps_term
///  female_x educ_x   dic_x  law_enforce_x  youth_league_x   org_x  prop_x 
* dummy variable of purge of city chief executives
replace  purge_city = 1 if purge_city >1

* set graph theme
set scheme plotplain 

* label variable variables
lab var sec_promotion "Political Turnover"
lab var cityID "Prefecture"
lab var xi_connection_purge "Xi's Client*Connection*Purge Intensity"
lab var xi_purge "Xi's Client*Purge Intensity"
lab var xi_connection "Xi's Client*Connection"
lab var  prov_xi_faction "Xi's Client"
lab var purgeconnection "Purge Intensity*Connection"
lab var first_con_ps "Connection"
*lab var total_purge "General Purge"
lab var purge_cen_cum "Purge Intensity"
lab var gdp_growth_rel "Relative GDP Growth Rate"
lab var fiscal_growth_rel "Relative Fiscal Growth Rate"
lab var gdp_pc_rel "Relative Economic Performance"
lab var fiscal_gdp_rel "Relative Fiscal Performance"
lab var sec_age "Age"
lab var sec_age_2 "Age^2"
lab var ps_term "Years in Office"
lab var ps_term_2 "Years in Office^2"
lab var female "Female"
lab var edu "College"
lab var dic "DIC"
lab  var minority "Minority"
lab var law_enforce "Court and Law Enforcement"
lab var org "Organization"
lab var prop "Propaganda"
lab var youth_league "Youth League"
lab var firstjob_yr "Years of Work Experience"
lab var party_yr "Years of Party Membership"
lab var roving  "Roving Inspection"
lab var prov_ps_term "Provincial Party Boss Term"
encode provID, gen(provID1)



// grstyle clear // clear the grstyle settings
// set scheme s2color // sets the color scheme
// grstyle init // initiates the gr style command
// grstyle set plain, box  // create a plain style, with a box around the plot
//     * 'grid' is another good option you can play with
// grstyle color background white // turn the background white
// grstyle set color mono // set a monochrome color scheme for points/lines
//   grstyle set color Dark2, n(3) // set a color scheme for colored lines/points
//     * other color schemes include Set1, Set2, RdYlGn, Dark1, Dark2
//     * I set the number of colors I need in the plot in ', n(3)'
//  //grstyle yesno draw_major_hgrid yes // include major grid lines
//  //grstyle yesno draw_major_ygrid yes // include major grid lines
// grstyle set legend 10// move the legend inside the plot area
//     * for this last command the number after legend refers to the corner 
//     * of the plot (1 to at least 12 like a clock). I wanted it in the upper
//     * left. I just played around with numbers til I got it where I wanted.
// grstyle set size 14pt: axis_title // change the size of axis text 
